import { Application, Session } from "mydog";
import { DEF } from "./definition/consts";
import sequelize from "../models";
import DBManager from "./dbManager";
import connectorManager from "./connectorManager";
import gateManager from "./gateManager";
import lobbyManager from "./lobbyManager";
import roomManager from "./roomManager";
import doudizhuManager from "./game/doudizhu/doudizhuManager";

export function serverInit(app: Application) {

  switch (app.serverType) {
    case DEF.SEVER.TYPE.GATE:
      gateManager.init(app);
      break;
    case DEF.SEVER.TYPE.CONNECTOR:
      connectorManager.init(app);
      app.route(DEF.SEVER.TYPE.DATABASE, (session: Session) => DEF.SEVER.ID.DATABASE);
      app.route(DEF.SEVER.TYPE.LOBBY, (session: Session) => DEF.SEVER.ID.LOBBY);
      app.route(DEF.SEVER.TYPE.ROOM, (session: Session) => DEF.SEVER.ID.ROOM);
      app.route(DEF.SEVER.TYPE.DOUDIZHU, (session: Session) => DEF.SEVER.ID.DOUDIZHU);
      break;
    case DEF.SEVER.TYPE.DATABASE:
      DBManager.init(app, sequelize);
      break;
    case DEF.SEVER.TYPE.LOBBY:
      lobbyManager.init(app);
      break;
    case DEF.SEVER.TYPE.ROOM:
      roomManager.init(app);
      break;
    case DEF.SEVER.TYPE.DOUDIZHU:
      doudizhuManager.init(app);
      break;
    default: break;
  }
}
